package com.uhu.tag;

import com.uhu.tag.dto.req.TagGroupSaveReqDTO;
import com.uhu.tag.dto.req.TagGroupUpdateReqDTO;
import com.uhu.tag.dto.res.TagGroupListByCategoryIdResDTO;
import com.uhu.tag.service.ITagGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liujunjie
 * @description 标签组相关接口
 * @create 2023-12-01
 **/
@Api(tags = "标签组相关接口")
@RestController
@RequestMapping("api/tag/tagGroup")
public class TagGroupController {
    @Autowired
    private ITagGroupService iTagGroupService;

    @ApiOperation("根据标签大类查询标签组接口")
    @GetMapping("list/{tagCategoryId}")
    public List<TagGroupListByCategoryIdResDTO> tagGroupListQueryByCategoryId(@PathVariable("tagCategoryId") Long tagCategoryId) {
        List<TagGroupListByCategoryIdResDTO> tagGroupListQueryByCategoryIdResDTOList = iTagGroupService.tagGroupListQueryByCategoryId(tagCategoryId);
        return tagGroupListQueryByCategoryIdResDTOList;
    }

    @ApiOperation("新增标签组接口")
    @PostMapping("save")
    public void saveTagGroup(@RequestBody @Validated TagGroupSaveReqDTO tagGroupSaveReqDTO) {
        iTagGroupService.saveTagGroup(tagGroupSaveReqDTO);
    }

    @ApiOperation("编辑标签组接口")
    @PostMapping("update")
    public void updateTagGroup(@RequestBody @Validated TagGroupUpdateReqDTO tagGroupUpdateReqDTO) {
        iTagGroupService.updateTagGroup(tagGroupUpdateReqDTO);
    }

    @ApiOperation("标签组排序")
    @PutMapping("sort/{tagCategoryId}")
    public void sortTagGroup(@RequestBody Long[] ids, @PathVariable("tagCategoryId") Long tagCategoryId) {
        iTagGroupService.sortTagGroup(ids, tagCategoryId);
    }

    @ApiOperation("标签组删除")
    @DeleteMapping("delete/{groupId}")
    public void deleteTagGroup(@PathVariable("groupId") Long groupId) {
        iTagGroupService.deleteTagGroup(groupId);
    }
}
